/**
 * @author lk
 * @date 2022/6/6 17:43
 */
package com.mmall.thread.abc;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class CallableTest01 {
    public static void main(String[] args) {
        PrintInfo printInfo = new PrintInfo();
        FutureTask<LocalDateTime> localDateTimeFutureTask = new FutureTask<>(printInfo);
        Thread thread = new Thread(localDateTimeFutureTask);
        thread.start();

        LocalDateTime localDateTime = getLocalDateTime(localDateTimeFutureTask);
        String time = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss").format(localDateTime);
        System.out.println(time);
    }

    private static LocalDateTime getLocalDateTime(FutureTask<LocalDateTime> localDateTimeFutureTask)  {
        LocalDateTime res = null;
        try {
            res = localDateTimeFutureTask.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return res;
    }


}

class PrintInfo implements Callable<LocalDateTime> {
    @Override
    public LocalDateTime call() throws Exception {
        for (int i = 0; i < 5; i++) {
            System.out.println(i);
        }
        return LocalDateTime.now();
    }
}
